package com.unswift.window.factory;

import java.awt.Color;
import java.awt.event.KeyListener;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

import com.unswift.utils.ObjectUtils;

public final class ScrollFactory {

	public static JScrollPane addScroll(JComponent comp, MouseListener mouseListener, KeyListener keyListener){
		JScrollPane scroll=new JScrollPane();
		scroll.setViewportView(comp);
		scroll.getViewport().setBackground(Color.WHITE);
		scroll.setBorder(BorderFactory.createEmptyBorder());
		if(ObjectUtils.isNotEmpty(mouseListener)){
			scroll.getViewport().addMouseListener(mouseListener);
		}
		if(ObjectUtils.isNotEmpty(keyListener)){
			scroll.getViewport().setFocusable(true);
			scroll.getViewport().addKeyListener(keyListener);
		}
		scroll.getVerticalScrollBar().setUnitIncrement(20);
		scroll.getHorizontalScrollBar().setUnitIncrement(20);
		return scroll;
	}
	
	public static JScrollPane addHScroll(JComponent comp){
		JScrollPane scroll=new JScrollPane();
		scroll.setViewportView(comp);
		scroll.getViewport().setBackground(Color.WHITE);
		scroll.setBorder(BorderFactory.createEmptyBorder());
		scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
		scroll.getHorizontalScrollBar().setUnitIncrement(20);
		return scroll;
	}
	
	public static JScrollPane addVScroll(JComponent comp){
		JScrollPane scroll=new JScrollPane();
		scroll.setViewportView(comp);
		scroll.getViewport().setBackground(Color.WHITE);
		scroll.setBorder(BorderFactory.createEmptyBorder());
		scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		scroll.getVerticalScrollBar().setUnitIncrement(20);
		return scroll;
	}
}
